package com.blog.controller.sys.register;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.blog.common.base.BaseController;
import com.blog.common.base.ResponseReslut;
import com.blog.common.constants.Constants;
import com.blog.entity.sys.User;
import com.blog.service.sys.UserService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("/register")
public class RegisterController extends BaseController {
	
	 @Autowired
	 private UserService userService;
	
	// 跳转注册页面
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String registerGet() {
		return "register/register";
	}
	
	

	
	
	/**
	 * 
	 * @author: chb
	 * @date: 2018年7月6日 下午3:16:07
	 * @param user
	 * @param reqest
	 * @return 
	 * 作用：   用户注册 
	 */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public String registerPost(User user,HttpServletRequest reqest)
    {
		 
		ResponseReslut result=userService.saveUser(user);
		//返回结果
		if(!result.getCode().equals(Constants.HTTP_RES_CODE_200))
		{
			reqest.setAttribute("error", "注册失敗");
			 return "redirect:/register";
		}
	     return "redirect:/login";
    }  

	
	
}
